//
//  GMHDataFiled.m
//  
//
//  Created by 郭明皓 on 15/10/31.
//
//

#import "GMHDataFiled.h"
#import <SDImageCache.h>
@implementation GMHDataFiled

+ (void)isHaveFileDocument
{
    //1.找沙盒路径
    NSString *sandboxpath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    //2.拼接电影的文件夹
    NSString *movieFile = [sandboxpath stringByAppendingPathComponent:@"Travel"];
    //3.创建一个文件管理者
    NSFileManager *manager = [NSFileManager defaultManager];
    //通过管理者调用方法,根据路径判断文件夹是否存在
    if (![manager fileExistsAtPath:movieFile]) {
        //创建文件夹
        [manager createDirectoryAtPath:movieFile withIntermediateDirectories:YES attributes:nil error:nil];
        
    }
    NSLog(@"%@", movieFile);

}

+(void)isHaveFileActivity
{
    //1.找沙盒路径
    NSString *sandboxpath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    //2.拼接电影的文件夹
    NSString *movieFile = [sandboxpath stringByAppendingPathComponent:@"Travel/Activity"];
    //3.创建一个文件管理者
    NSFileManager *manager = [NSFileManager defaultManager];
    //通过管理者调用方法,根据路径判断文件夹是否存在
    if (![manager fileExistsAtPath:movieFile]) {
        //创建文件夹
        [manager createDirectoryAtPath:movieFile withIntermediateDirectories:YES attributes:nil error:nil];
        
    }
    NSLog(@"%@", movieFile);
}

+ (void)isHaveFileFind
{
    //1.找沙盒路径
    NSString *sandboxpath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    //2.拼接电影的文件夹
    NSString *movieFile = [sandboxpath stringByAppendingPathComponent:@"Travel/Find"];
    //3.创建一个文件管理者
    NSFileManager *manager = [NSFileManager defaultManager];
    //通过管理者调用方法,根据路径判断文件夹是否存在
    if (![manager fileExistsAtPath:movieFile]) {
        //创建文件夹
        [manager createDirectoryAtPath:movieFile withIntermediateDirectories:YES attributes:nil error:nil];
        
    }
    NSLog(@"%@", movieFile);
}

+ (void)isHaveFileSurround
{
    //1.找沙盒路径
    NSString *sandboxpath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
    //2.拼接电影的文件夹
    NSString *movieFile = [sandboxpath stringByAppendingPathComponent:@"Travel/Surround"];
    //3.创建一个文件管理者
    NSFileManager *manager = [NSFileManager defaultManager];
    //通过管理者调用方法,根据路径判断文件夹是否存在
    if (![manager fileExistsAtPath:movieFile]) {
        //创建文件夹
        [manager createDirectoryAtPath:movieFile withIntermediateDirectories:YES attributes:nil error:nil];
        
    }
    NSLog(@"%@", movieFile);

}
+(float)folderSizeAtPath:(NSString *)path{
    NSFileManager *fileManager=[NSFileManager defaultManager];
    float folderSize;
    if ([fileManager fileExistsAtPath:path]) {
//        NSArray *childerFiles=[fileManager subpathsAtPath:path];
//        for (NSString *fileName in childerFiles) {
//            NSString *absolutePath=[path stringByAppendingPathComponent:fileName];
//            folderSize +=[self fileSizeAtPath:absolutePath];
//            
//        }
        
    //SDWebImage框架自身计算缓存的实现
        folderSize+=[[SDImageCache sharedImageCache] getSize]/1024.0/1024.0;
        return folderSize;
    }
    return 0;
}

+(void)clearCache:(NSString *)path{
    NSFileManager *fileManager=[NSFileManager defaultManager];
    if ([fileManager fileExistsAtPath:path]) {
        NSArray *childerFiles=[fileManager subpathsAtPath:path];
        for (NSString *fileName in childerFiles) {
            //如有需要，加入条件，过滤掉不想删除的文件
            NSString *absolutePath=[path stringByAppendingPathComponent:fileName];
            [fileManager removeItemAtPath:absolutePath error:nil];
        }
    }
    [[SDImageCache sharedImageCache] cleanDisk];
}



@end
